<?php

namespace app\common\model\goods;

use app\common\model\User;
use think\Model;


class Review extends Model
{

    

    

    // 表名
    protected $name = 'goods_review';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'images_array',
        'createtime_text',
    ];
    

    public function getCreatetimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['createtime']) ? $data['createtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    
    public function getImagesArrayAttr($v, $d)
    {
        if (isset($d['images']) && $d['images']) {
            $array = explode(',', $d['images']);
            foreach ($array as &$value) {
                $value = $value ? cdnurl($value, true) : '';
            }
            return $array;
        }
        return [];
    }



    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }



}
